#!/bin/sh

# Get the major number of the megadev ioctl device node
megadev_major=$(egrep '[[:space:]]megadev(_legacy)?$' /proc/devices 2>/dev/null | awk '{print $1}' 2>/dev/null)
megadev_node=/dev/megadev0

# MegaRAID device node major number found
if [ -z "${megadev_major}" ]; then
	echo "ERROR: failed to determine device node major number"
	exit 1
fi
if [ -e "${megadev_node}" ]; then
	if ! rm -f "${megadev_node}"; then
		echo "ERROR: failed to remove existing device node ${megadev_node}"
		exit 1
	fi
fi
if ! mknod "${megadev_node}" c "${megadev_major}" 0; then
	echo "ERROR: failed to create device node ${megadev_node}"
	exit 1
fi

# Start the real dellmgr binary
"${0%/*}/dellmgr.bin" "${@}"
